home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks96
/
InternetChooser.sit
/
Internet Chooser
/
main.cp
< prev
next >
Wrap
Text File
|
1996-06-22
|
12KB
|
447 lines
#include <string.h>
#include <ctype.h>
#include "stdtypes.h"
#include "stddebug.h"
#include "client.h"
#include "datagram.h"
#include "platform.h"
#include "reggie.h"
#include "socket.h"
#include "ICAPI.h"
#include "main.h"
// Globals
Str255 gInfo = "\pThe Internet Chooser by Matt and Mike!";
DialogPtr gChooserDialogPtr;
Boolean gQuitting;
ListHandle gServiceList;
ListHandle gURLList;
short gFilterValue;
extern RegEntry gRegStore[kRegEntryCount];
extern UInt32 gRegCount;
ICInstance gICInst;
CursHandle gWatch = 0;
// * *******************************************************************************
// * *******************************************************************************
void main(void) {
OSErr err = noErr;
Initialize();
SetUpMenus();
if(SetUpChooser())
while(!gQuitting)
err = EventLoop();
DisposDialog(gChooserDialogPtr);
}
// * *******************************************************************************
// * *******************************************************************************
void SetUpMenus(void) {
InsertMenu(GetMenu(128), 0);
AddResMenu(GetMHandle(128), 'DRVR');
InsertMenu(GetMenu(129), 0);
InsertMenu(GetMenu(130), 0);
DisableItem(GetMenu(130), 1);
DisableItem(GetMenu(130), 2);
DisableItem(GetMenu(130), 3);
DisableItem(GetMenu(130), 4);
DrawMenuBar();
}
// * *******************************************************************************
// * *******************************************************************************
DialogPtr SetUpChooser(void) {
Rect ServiceRect, URLRect, InfoRect, ServiceListBounds, URLListBounds;
short iType, i=0, j=-1, row, total=0;
Handle iHandle, aServiceIcon;
Point serviceCellSize, URLCellSize;
Ptr cellData;
StringHandle iconString;
Cell currentCell;
OSErr err=noErr;
GrafPtr oldPort;
GetPort(&oldPort);
if(gChooserDialogPtr = GetNewDialog(128, NULL, (WindowPtr)-1)) {
SetPort(gChooserDialogPtr);
GetDItem(gChooserDialogPtr, kServiceList, &iType, &iHandle, &ServiceRect);
GetDItem(gChooserDialogPtr, kURLList, &iType, &iHandle, &URLRect);
SetRect(&ServiceListBounds, 0, 0, 3, 3);
SetPt(&serviceCellSize, 60, 60);
gServiceList = LNew(&ServiceRect, &ServiceListBounds, serviceCellSize, 130, gChooserDialogPtr,
TRUE, FALSE, FALSE, TRUE);
SetRect(&URLListBounds, 0, 0, 1, 10);
SetPt(&URLCellSize, 0, 0);
gURLList = LNew(&URLRect, &URLListBounds, URLCellSize, 0, gChooserDialogPtr,
TRUE, FALSE, FALSE, TRUE);
cellData = NewPtr(sizeof(char)*64);
if(MemError())
return(0);
i=128;
total = Count1Resources('STR ');
for(i=0; (i*3)+j<total; i++, j=0) {
for(j=0; (j<3) && ((i*3)+j<total);j++) {
GetIconSuite(&aServiceIcon, (i*3)+j+128, svAllAvailableData);
iconString = GetString((i*3)+j+128);
if(!iconString)
break;
SetPt((Point *)(¤tCell), j, i);
BlockMove(&aServiceIcon, cellData, sizeof(Handle));
BlockMove((*iconString)+1, cellData+sizeof(Handle), (*iconString)[0]);
LSetCell(cellData, (*iconString)[0]+sizeof(Handle), currentCell, gServiceList);
ReleaseResource((Handle)iconString);
if(ResError())
return(0);
}
}
ShowWindow((WindowPtr)gChooserDialogPtr);
SetPort(oldPort);
}
DisposePtr(cellData);
return(gChooserDialogPtr);
}
// * *******************************************************************************
// * *******************************************************************************
//Initialize the ToolBox
void Initialize(void) {
WindowPtr mainPtr;
OSErr error;
SysEnvRec theWorld;
gQuitting = FALSE;
error = SysEnvirons(1, &theWorld);
if (theWorld.hasColorQD == false) {
SysBeep(50);
ExitToShell(); /* If no color QD, we must leave. */
}
/* Initialize all the needed managers. */
InitGraf(&qd.thePort);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(nil);
InitCursor();
MoreMasters();
MoreMasters();
MoreMasters();
gWatch = GetCursor(watchCursor);
ICStart(&gICInst, 'MSMM');
ICFindConfigFile(gICInst, 0, NULL);
}
// * *******************************************************************************
// * *******************************************************************************
void ChangeURLList(short index) {
short i=0, iType;
Cell curCell;
Rect iRect;
Handle iHandle;
RgnHandle infoRgn = NewRgn();
StringHandle ourString;
char state;
Str32 typeMask;
ourString = GetString(128+index);
for(i=1;i<=((*ourString)[0]);i++)
(*ourString)[i] = tolower((*ourString)[i]);
BlockMove((*ourString)+1, typeMask, (*ourString)[0]);
typeMask[(*ourString)[0]] = 0;
state = HGetState((Handle)ourString);
HLock((Handle)ourString);
QueryTracker(0x12345678, 0, 100, (char *)typeMask, NULL, NULL,
"sils.umich.edu");
HSetState((Handle)ourString, state);
LDelRow(0, 0, gURLList);
GetDItem(gChooserDialogPtr, kInfoField, &iType, &iHandle, &iRect);
RectRgn(infoRgn, &iRect);
InvalRgn(infoRgn);
BlockMove("\p", gInfo, 1);
for(i=0;i<gRegCount;i++) {
LAddRow(1, i, gURLList);
SetPt(&curCell, 0, i);
LSetCell(gRegStore[i].serviceName, strlen(gRegStore[i].serviceName), curCell, gURLList);
}
ReleaseResource((Handle)ourString);
DisposeRgn(infoRgn);
}
// * *******************************************************************************
// * *******************************************************************************
void DoMouseInDialog(EventRecord theEvent, short theItem) {
long result=0;
GrafPtr oldPort;
Handle filterPopUp;
short iType;
Rect iRect;
RgnHandle infoRgn = NewRgn();
Point localPt;
Cell ourCell;
long length, start=0;
GetPort(&oldPort);
SetPort((GrafPtr)gChooserDialogPtr);
localPt = theEvent.where;
GlobalToLocal(&localPt);
switch(theItem) {
case kServiceList:
case kServiceListScroll:
if (gWatch) SetCursor(*gWatch);
LClick(localPt, theEvent.modifiers, gServiceList);
SetPt(&ourCell, 0, 0);
LGetSelect(TRUE, &ourCell, gServiceList);
ChangeURLList((ourCell.v*3)+ourCell.h);
break;
case kURLList:
case kURLListScroll:
SetPt(&ourCell, 0, 0);
if(LClick(localPt, theEvent.modifiers, gURLList)) {
if (gWatch) SetCursor(*gWatch);
LGetSelect(TRUE, &ourCell, gURLList);
length = strlen(gRegStore[ourCell.v].serviceName);
if(result = ICLaunchURL(gICInst, "\p",
gRegStore[ourCell.v].serviceName,
length, &start, &length)) SysBeep(4);
}
if(LGetSelect(TRUE, &ourCell, gURLList)) {
BlockMove(gRegStore[ourCell.v].serviceInfo, gInfo+1,
gInfo[0]=strlen(gRegStore[ourCell.v].serviceInfo));
GetDItem(gChooserDialogPtr, kInfoField, &iType, &filterPopUp, &iRect);
RectRgn(infoRgn, &iRect);
InvalRgn(infoRgn);
}
else {
BlockMove("\p", gInfo, 1);
GetDItem(gChooserDialogPtr, kInfoField, &iType, &filterPopUp, &iRect);
RectRgn(infoRgn, &iRect);
InvalRgn(infoRgn);
}
break;
case kFilterMenu:
GetDItem(gChooserDialogPtr, kFilterMenu, &iType, &filterPopUp, &iRect);
gFilterValue = GetCtlValue((ControlHandle)filterPopUp);
GetDItem(gChooserDialogPtr, kInfoField, &iType, &filterPopUp, &iRect);
RectRgn(infoRgn, &iRect);
InvalRgn(infoRgn);
default:
break;
}
DisposeRgn(infoRgn);
SetPort(oldPort);
}
// * *******************************************************************************
// * *******************************************************************************
void DoMouseOutsideDialog(EventRecord theEvent, short theItem) {
short winPart;
GrafPtr oldPort;
long menuStuff;
WindowPtr testWindow;
GetPort(&oldPort);
SetPort((GrafPtr)gChooserDialogPtr);
winPart = FindWindow(theEvent.where, &testWindow);
switch(winPart) {
case inMenuBar:
menuStuff = MenuSelect(theEvent.where);
if(menuStuff)
DoMenu(HiWord(menuStuff), LoWord(menuStuff));
break;
case inDrag:
DragWindow((WindowPtr)gChooserDialogPtr, theEvent.where, &(qd.screenBits.bounds));
break;
case inGoAway:
if(TrackGoAway(gChooserDialogPtr, theEvent.where))
gQuitting = TRUE;
break;
default:
break;
}
SetPort(oldPort);
}
// * *******************************************************************************
// * *******************************************************************************
void DoKey(EventRecord theEvent, short theItem) {
GrafPtr oldPort;
GetPort(&oldPort);
SetPort((GrafPtr)gChooserDialogPtr);
//Do Stuff...
SetPort(oldPort);
}
// * *******************************************************************************
// * *******************************************************************************
void DoMenu(short menuID, short menuItem) {
GrafPtr oldPort;
Str255 DAName;
GetPort(&oldPort);
SetPort((GrafPtr)gChooserDialogPtr);
if((menuID == 0) && (menuItem < 0)) {
GetItem(GetMHandle(128), menuItem, DAName);
OpenDeskAcc(DAName);
}
if(menuID == 129) { //File Menu...
gQuitting = TRUE;
}
if(menuID == 130) { //Edit Menu...
//Everything is disabled...
}
HiliteMenu(0);
SetPort(oldPort);
}
// * *******************************************************************************
// * *******************************************************************************
OSErr EventLoop(void) {
DialogPtr myDlg;
short theItem;
EventRecord theEvent;
Boolean handled = FALSE, inDialog = TRUE;
long menuStuff;
GrafPtr oldPort;
if(WaitNextEvent(everyEvent, &theEvent, 30, NULL)) {
GetPort(&oldPort);
SetPort(gChooserDialogPtr);
TextFont(0);
TextSize(0);
SetPort(oldPort);
if ((theEvent.what != updateEvt) && (inDialog=IsDialogEvent(&theEvent)))
handled = !DialogSelect(&theEvent, &myDlg, &theItem);
GetPort(&oldPort);
SetPort(gChooserDialogPtr);
TextFont(1);
TextSize(9);
SetPort(oldPort);
if(handled == FALSE) {
switch(theEvent.what) {
case mouseDown:
if(inDialog)
DoMouseInDialog(theEvent, theItem);
else
DoMouseOutsideDialog(theEvent, theItem);
break;
case keyDown:
DoKey(theEvent, theItem);
break;
case updateEvt:
DoUpdate();
break;
case nullEvent:
default:
break;
}
}
else {
if((theEvent.modifiers & cmdKey)&&(theEvent.what == keyDown))
menuStuff = MenuKey(theEvent.message & charCodeMask);
if(menuStuff) {
HiliteMenu(HiWord(menuStuff));
DoMenu(HiWord(menuStuff), LoWord(menuStuff));
}
}
SetCursor(&qd.arrow);
}
return noErr;
}
// * *******************************************************************************
// * *******************************************************************************
void DoUpdate(void) {
GrafPtr oldPort;
Rect ServiceRect, URLRect, InfoRect;
short iType;
Handle iHandle;
GetPort(&oldPort);
SetPort(gChooserDialogPtr);
GetDItem(gChooserDialogPtr, kServiceList, &iType, &iHandle, &ServiceRect);
GetDItem(gChooserDialogPtr, kURLList, &iType, &iHandle, &URLRect);
GetDItem(gChooserDialogPtr, kInfoField, &iType, &iHandle, &InfoRect);
BeginUpdate(gChooserDialogPtr);
UpdtDialog(gChooserDialogPtr, gChooserDialogPtr->visRgn);
InsetRect(&ServiceRect, -1, -1);
InsetRect(&URLRect, -1, -1);
FrameRect(&ServiceRect);
FrameRect(&URLRect);
PenPat(&qd.gray);
FrameRect(&InfoRect);
PenPat(&qd.black);
LUpdate((*gServiceList)->port->visRgn, gServiceList);
LUpdate((*gURLList)->port->visRgn, gURLList);
InsetRect(&InfoRect, 2, 2);
//NumToString(gFilterValue, gInfo);
TextBox(&(gInfo[1]), gInfo[0], &InfoRect, 0);
EndUpdate(gChooserDialogPtr);
SetPort(oldPort);
}